package com.jungle.client;

import com.google.gson.reflect.TypeToken;
import com.jungle.bfi.domain.vo.DataDefinitionVo;
import com.jungle.client.channel.HttpClient;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TableView;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

@Slf4j
public class BizBillController implements Initializable {
    @FXML
    private TableView<DataDefinitionVo> tableView;

    @Override
    public void initialize(java.net.URL location, java.util.ResourceBundle resources) {
        log.info("init BizBillController, location:{}", location);
        loadData();
    }

    @FXML
    private void refresh() {
        log.info("BizBillController.refresh");
        loadData();
    }

    private void loadData() {
        log.info("BizBillController.loadData");
        HttpClient.getInstance().post("/dataDefinition/bizBillTypeList", "{}").callback(new TypeToken<List<DataDefinitionVo>>() {
        }, list -> {
            log.info("resp: {}", list);
            if (list != null && !list.isEmpty()) {
                tableView.getItems().clear();
                tableView.getItems().addAll(list);
            }
        });
    }
}
